//
//  ViewController.m
//  08-核心动画-cakeyframeanimation
//
//  Created by J on 16/2/23.
//  Copyright © 2016年 J. All rights reserved.
//

#import "ViewController.h"
#define angle2Random(angle) ((angle)/180.0*M_PI)
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *imageView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    
   
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    //添加核心动画
    CAKeyframeAnimation* ani = [CAKeyframeAnimation animation];
//    ani.keyPath = @"transform.rotation";
        ani.keyPath = @"position";
    //让动画绕着路径走
    ani.path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(30, 30, 100, 100)].CGPath;
    
    ani.values = @[@(angle2Random(-5)),@(angle2Random(10)),@(angle2Random(-5))];
    ani.repeatCount = CGFLOAT_MAX;
    _imageView.layer.anchorPoint = CGPointZero;
    [_imageView.layer addAnimation:ani forKey:nil];
    

}


@end
